<template>
  <div class="header">
    <!-- 头部的第一行 -->
    <div class="top">
      <div class="container">
        <div class="loginList">
          <p v-if="isLogged">
            <span>感谢您选择汽车之家! </span>
            <a class="quitLog" @click="quitLog()">退出登录</a>
          </p>
          <p v-else>
            <span>汽车之家欢迎您！ 请</span>
            <router-link to="/login">登录</router-link>
          </p>
        </div>
        <div class="typeList">
          <a class="linkTo" @click="toManage">管理文章</a>
          <a class="linkTo" @click="toPublish">发布文章</a>
          <a href="http://101.43.12.19:8080">商家后台</a>
        </div>
      </div>
    </div>
    <!--头部第二行 搜索区域-->
    <div class="bottom">
      <h1 class="logoArea">
        <router-link class="logo" to="/home">
          <img src="./images/logo.jpg" alt="">
        </router-link>
      </h1>
      <div class="searchArea" v-if="!this.$root.isInLogPage">
        <form action="#" class="searchForm">
          <input type="text" id="autocomplete" class="input-error input-xxlarge" v-model="keyword"/>
          <button class="sui-btn btn-xlarge btn-danger" type="button" @click="search">搜索</button>
        </form>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "index",
  data() {
    return {
      keyword: '',
      isLogged: this.GLOBALVAR.isLogged,
    }
  },
  methods: {
    search() {
      if (this.keyword !== '') {
        this.$router.push({
          name: 'search',
          params: {
            keyword: this.keyword
          }
        })
      }
    },
    quitLog() {
      this.GLOBALVAR.isLogged = false
      this.$router.push("/login")
      this.$message({
        message: '您已退出登录，期待您的下次光临',
        type: 'info'
      });
    },
    toManage() {
      if (!this.GLOBALVAR.isLogged) {
        this.$message.info("您必须登录后才可以进行该操作!");
        this.$router.push("/login");
      } else {
        this.$router.push("/article/my");
      }
    },
    toPublish() {
      if (!this.GLOBALVAR.isLogged) {
        this.$message.info("您必须登录后才可以进行该操作!");
        this.$router.push("/login");
      } else {
        this.$router.push("/arti/edit");
      }
    }
  }
}
</script>

<style lang="less" scoped>
.header {
  &>.top {
    background-color: #eaeaea;
    height: 30px;
    line-height: 30px;

    .container {
      width: 1200px;
      margin: 0 auto;
      overflow: hidden;

      .loginList {
        float: left;

        p {
          float: left;
          margin-right: 10px;

          .register {
            border-left: 1px solid #b3aeae;
            padding: 0 5px;
            margin-left: 5px;
          }
        }
      }

      .typeList {
        float: right;

        a {
          padding: 0 10px;

          &+a {
            border-left: 1px solid #b3aeae;
          }
        }

      }

    }
  }

  &>.bottom {
    width: 1200px;
    margin: 0 auto;
    overflow: hidden;

    .logoArea {
      float: left;

      .logo {
        img {
          width: 210px;
          margin: 0 45px;
        }
      }
    }

    .searchArea {
      float: right;
      margin-top: 55px;
      margin-right: 30px;

      .searchForm {
        overflow: hidden;

        input {
          box-sizing: border-box;
          width: 490px;
          height: 38px;
          padding: 0 4px;
          border: 2px solid #ea4a36;
          float: left;

          &:focus {
            outline: none;
          }
        }

        button {
          height: 38px;
          width: 68px;
          background-color: #ea4a36;
          border: none;
          color: #fff;
          float: left;
          cursor: pointer;

          &:focus {
            outline: none;
          }
        }
      }
    }
  }
}

.quitLog:hover {
  cursor: pointer;
  text-decoration: underline;
}

.linkTo:hover {
  cursor: pointer;
  text-decoration: underline;
}
</style>
